/*
 *  POJ2255: Tree Recovery
 */

/*-------- Includes --------*/
#include <iostream>
#include <cstring>

using namespace std;

/*-------- Types --------*/
struct Node {
    char c;
    Node *l;
    Node *r;

public:
    Node() : c(0), l(NULL) ,r(NULL) {}
    ~Node() {
        delete l; l = NULL;
        delete r; r = NULL;
    }
};

/*-------- Function Prototypes --------*/
Node *construct(const char *pre, const char *in, int n);
void posttr(Node *root);

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    char cstr1[32]; // pre-order traversal string
    char cstr2[32]; // in-order traversal string

    while (cin >> cstr1 >> cstr2) {
        Node *root = NULL;
        int  n     = strlen(cstr1);

        root = construct(cstr1, cstr2, n);

        // post traverse: print
        posttr(root); cout << endl;

        delete root;
    }

    return 0;
}

/*-------- Functions --------*/
Node *construct(const char *pre, const char *in, int n)
{
    // base case
    if (n == 0) return NULL;

    Node *root = new Node;

    // root value
    char rt = pre[0];

    root->c = rt;

    int nl = -1;

    // find root in in-order traversal string
    for (int i = 0; i < n; i++) {
        if (in[i] == rt) {
            nl = i;
            break;
        }
    }

    // left subtree
    root->l = construct(pre + 1, in, nl);

    // right tree
    root->r = construct(pre + nl + 1, in + nl + 1, n - 1 - nl);

    return root;
}

void posttr(Node *root)
{
    if (root == NULL) return;

    posttr(root->l);
    posttr(root->r);
    cout << root->c;
}
